import React, { Component } from 'react';

import { requireNativeComponent } from 'react-native';

const RCTQiniuPlayer = requireNativeComponent('RCTQiniuPlayer', QiniuPlayer);

export default class QiniuPlayer extends Component {

    constructor(props) {
        super(props);
        this.onLoading = this.onLoading.bind(this);
        this.onPaused = this.onPaused.bind(this);
        this.onShutdown = this.onShutdown.bind(this);
        this.onError = this.onError.bind(this);
        this.onPlaying = this.onPlaying.bind(this);
    }

    onLoading(event) {
        this.props.onLoading && this.props.onLoading(event.nativeEvent);
    }

    onPaused(event) {
        this.props.onPaused && this.props.onPaused(event.nativeEvent);
    }

    onShutdown(event) {
        this.props.onShutdown && this.props.onShutdown(event.nativeEvent);
    }

    onError(event) {
        this.props.onPlayerError && this.props.onPlayerError(event.nativeEvent);
    }

    onPlaying(event) {
        this.props.onPlaying && this.props.onPlaying(event.nativeEvent);
    }

    render() {
        const nativeProps = Object.assign({}, this.props, {
            onLoading: this.onLoading,
            onPaused: this.onPaused,
            onShutdown: this.onShutdown,
            onPlayerError: this.onError,
            onPlaying: this.onPlaying,
        });

        return (
            <RCTQiniuPlayer{...nativeProps}/>
        );
    }
}
